<?php $this->load->view('admin/header.php');?>

<div class="columns clr">
	<div class="side-col">
		<ul id="dish_form_tabs" class="tabs">
			<li><a id="dish_form_tabs_group_" class="tab-item-link" href="javascript:void(0)">
			</a></li>
		</ul>
	</div>
	<div class="main-col">
		<div class="main-col-inner">
			<div class="content-header clr">
				<h3>Edit '<?php echo $data['name'];?>'</h3>
				<p class="form-buttons">
					<button id="id_2008838876113115" title="Back" class="back scalable" type="button" onclick="javascript:history.go(-1)"><span>Back</span></button>
					<button id="id_0120276870624159" title="Reset" class="scalable" type="button" onclick="setLocation(window.location.href)"><span>Reset</span></button>
					<button id="id_3364957056054962" title="Save" class="save scalable" type="button" onclick="dish_formForm.submit();"><span>Save</span></button>
				</p>
			</div>
			<div class="entry-edit">
				<form id="dish_form" class="form" action="<?php echo $action;?>" enctype="multipart/form-data" method="post">
					<div>
						<input type="hidden" value="" name="ci_csrf_token">
					</div>
					<div id="dish_form_tabs_group__content" class="tab_content" style="">
						<div class="entry-edit-head clr">
							<h4></h4>
						</div>
						<div id="" class="fieldset">
							<div class="hor-scroll">
								<table class="form-list" cellspacing="0">
								<tbody>
								<tr>
									<td class="label">
										<label for="name">Món ăn</label>
									</td>
									<td class="value">
										<input id="name" class="text" type="text" value="<?php echo $data['name'];?>" name="name">
									</td>
								</tr>
								<tr>
									<td class="label">
										<label for="alias">alias</label>
									</td>
									<td class="value">
										<input id="alias" class="text " type="text" value="<?php echo $data['alias'];?>" name="alias">
									</td>
								</tr>
								<tr>
									<td class="label">
										<label for="introtext">Giới thiệu</label>
									</td>
									<td class="value">
										<textarea id="introtext" name="introtext" class="textarea"><?php echo $data['introtext'];?></textarea>
									</td>
								</tr>
								<tr>
									<td class="label">
										<label for="is_hot">Hot <span class="required">*</span></label>
									</td>
									<td class="value">
										<?php echo $select['is_hot'];?>
									</td>
								</tr>
								<tr>
									<td class="label">
										<label for="status">Trạng thái</label>
									</td>
									<td class="value">
										<?php echo $select['status'];?>
									</td>
								</tr>
								<tr>
									<td class="label">
										<label for="image1">image1</label>
									</td>
									<td class="value">
										<a onclick="imagePreview('image1_image'); return false;" href="<?php echo base_url($data['image1']);?>">
											<img class="small-image-preview v-middle" width="50" height="50" id="image1_image" src="<?php echo $data['image1'];?>">
										</a>
										<input type="file" class="" id="image1" name="image1">
										<input type="hidden" id="image1_value" name="image1_value" value="<?php echo $data['image1'];?>">
										<span class="delete-image">
										<input type="checkbox" name="image1_delete" id="image1_delete">
										<label for="image1_delete">Delete File</label></span>
									</td>
								</tr>
								<tr>
									<td class="label">
										<label for="stock">Nguyên liệu</label>
									</td>
									<td class="value">
										<style type="text/css">
											.item 
											{
												margin-top: 5px;
											}
											.item input
											{
												margin-right: 5px;
											}

											.item-step {
												margin-top: 5px;	
											}

											.item-step input {
												margin-top: 5px;
											}

											.item-step img {
												width: 280px;
												height: 200px;
												display: none;
											}

										</style>
										<script type="text/javascript">
										(function($) {
											$(document).ready(function() {
												
											});
											
										})(jQuery);

										function readURL(input, id) {
										   if (input.files && input.files[0]) {
											   var reader = new FileReader();
											   reader.onload = function(e) {
												   jQuery('#image_'+id).attr('src', e.target.result);
												   jQuery('#image_'+id).css("display", "block");
											   }
											   reader.readAsDataURL(input.files[0]);
										   }
										}
										</script>
										<div id="InputsWrapper">
										<?php 
										for ($i=0; $i < 12; $i++) {
											$stock = isset($data['stocks'][$i]['stock']) ? $data['stocks'][$i]['stock'] : '';
											$count = isset($data['stocks'][$i]['count']) ? $data['stocks'][$i]['count'] : '';
										?>
											<div class="item">
												<input type="text" name="stock[]" id="field_1" value="<?php echo $stock;?>" placeholder="Nguyên liệu"/>
												<input type="text" name="count[]" id="count_1" value="<?php echo $count;?>" placeholder="Số lượng"/>
											</div>
										<?php
										}
										?>
										</div>
										<a href="javascript:void(0)" id="AddMoreFileBox">Thêm Nguyên liệu</a>
									</td>
								</tr>
								<tr>
									<td class="label">
										<label for="step">Các bước thực hiện</label>
									</td>
									<td class="value">
										<div id="StepWrapper">
										<?php 
										for ($i=0; $i < 12; $i++) {
											$image = isset($data['steps'][$i]['image']) ? $data['steps'][$i]['image'] : '';
											$display = (isset($data['steps'][$i]['image']) && $data['steps'][$i]['image'] != '') ? ' style="display:block"' : '';
											$comment = isset($data['steps'][$i]['comment']) ? $data['steps'][$i]['comment'] : '';
										?>
											<div class="item-step">
												<strong>Bước <?php echo $i+1;?> </strong><br/>
												<input type="file" name="filePhoto_<?php echo $i;?>" onchange="readURL(this, '<?php echo $i;?>')"/>
												<br/><img id="image_<?php echo $i;?>" src="<?php echo $image;?>" <?php echo $display;?>/>
												<input type="hidden" name="h_filePhoto_<?php echo $i;?>" value="<?php echo $image;?>">
												<input type="text" class="text" name="step_<?php echo $i;?>" value="<?php echo $comment;?>" placeholder="Mô tả thực hiện"/>
											</div>
										<?php
										}
										?>
										</div>
									</td>
								</tr>
								<tr>
									<td class="label">
										<label for="fulltext">Lưu ý</label>
									</td>
									<td class="value">
										<textarea id="fulltext" name="fulltext" class="textarea"><?php echo $data['fulltext'];?></textarea>
									</td>
								</tr>
								<tr>
									<td class="label">
										<label for="prepTime">Thời gian chuẩn bị</label>
									</td>
									<td class="value">
										<input id="prepTime" class="text" type="text" value="<?php echo $data['prepTime'];?>" placeholder="Số phút" name="prepTime">
									</td>
								</tr>
								<tr>
									<td class="label">
										<label for="cookTime">Thời gian chế biến</label>
									</td>
									<td class="value">
										<input id="cookTime" class="text" type="text" value="<?php echo $data['cookTime'];?>" placeholder="Số phút" name="cookTime">
									</td>
								</tr>
								<tr>
									<td class="label">
										<label for="recipeYield">Số người ăn</label>
									</td>
									<td class="value">
										<input id="recipeYield" class="text" type="text" value="<?php echo $data['recipeYield'];?>" placeholder="Số người" name="recipeYield">
									</td>
								</tr>
								<tr>
									<td class="label">
										<label for="category_id">Loại món ăn <span class="required">*</span></label>
									</td>
									<td class="value">
										<?php
											unset($categories[4]);
											$count_child = 0;
											$i = 0;
											foreach ($categories as $key => $value) {
												if ($value['children'] > 0) {
													$count_child = $value['children'];
													// mo
													echo '<div class="item-cate">';
													echo '<strong>' . $value['name'] . '</strong><br/>';
												} else {
													$i++;

													$checked = '';
													if (isset($data['category_ids'])) {
														foreach ($data['category_ids'] as $k => $v) {
															if ($key == $v) {
																$checked = "checked='checked'";
															}
														}
													}
													
													echo "<input name='category_id[]' type='checkbox' value='".$key."' ".$checked."/>". $value['name'] . '<br/>';
												}

												if ($i == $count_child) {
													// dong
													echo '</div>';
													$count_child = 0;
													$i = 0;
												}
											}
										?>
									</td>
								</tr>
								<tr>
									<td class="label">
										<label for="tags">Tags</label>
									</td>
									<td class="value">
										<input id="tags" class="text" type="text" value="<?php echo $data['tags'];?>" placeholder="Mỗi tag cách nhau bằng dấu ," name="tags">
									</td>
								</tr>
								<tr>
									<td class="label">
										<label for="tags">Nguồn</label>
									</td>
									<td class="value">
										<?php if(isset($data['source'])) {?>
											<a target="_blank" href="<?php echo $data['source']; ?>"><?php echo $data['source']; ?></a>
										<?php }?>
									</td>
								</tr>
								</tbody>
								</table>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
//<![CDATA[ 
 dish_formForm = new varienForm('dish_form','') ; 
//]]>
</script>

<?php $this->load->view('admin/footer.php');?>